<template>
	<view class="box">	
		<view><input type="text" v-model="wallAddress" :placeholder="$t('money.withDraw.address')"></view>
		<view class="ti"><input type="number" v-model="quantity" :placeholder="$t('money.withDraw.withDrawl')"><text class="danwei">HNT</text><text class="all" @click="all">{{$t('money.withDraw.all')}}</text></view>
		<view class="use">{{$t('money.withDraw.usable')}}:{{use || 0}} HNT</view>
		<!-- <view class="getMoney">{{$t('money.withDraw.received')}}:<text class="money">{{quantity}}</text>USDT</view> -->
		<!-- <view class="service">{{$t('money.withDraw.commission')}}:{{serviceCharge}} USDT</view> -->
		<button type="default" @click="HNT">{{$t('money.withDraw.confirm')}}</button>
	</view>
</template>

<script>
	import api from '../../common/api.js'
	export default {
		data() {
			return {
				serviceCharge:1,
				quantity:'',
				wallAddress:'',
				use:'',
				show: false,
				msg:'',
			}
		},
		watch: {
			'quantity': function(val) {
				console.log(+val) 
				
				if(+val > this.use) {
					uni.showToast({
						title:'可用余额不足',
						icon:'none'
					})
					setTimeout(() => {
						this.all()
					}, 1000)
				}
			}
		},
		methods:{
			all(){
				this.quantity=this.use
			},
			HNT(){
				if(!this.wallAddress) {
					uni.showToast({
							title:'请输入钱包地址',
							icon:'none'
						})
					return
				}
				if(!this.quantity || +this.quantity == 0){
						uni.showToast({
							title:'请输入提币数',
							icon:'none'
						})
					return
				}
				uni.showLoading()
				this.$api.sendRequest({
					url:api.WITHDRAW_COIN,
					data:{
						cointype:'HNT',
						amount:this.quantity
					},
					success:res=>{
						uni.hideLoading()
						uni.showToast({
							title: res.msg,
							icon: res.code ? 'success' : 'none'
						})
						if(res.code==1){
							setTimeout(()=>{
								uni.switchTab({
									url:'../../pages/mine/mine'
								})
							},2000)
						}
					}
					
				})
			}
		},
		mounted() {
			this.$api.sendRequest({
				url:api.MINE_userId,
				success:res=>{
					this.use=res.data.welcome.HNT
					this.wallAddress=res.data.welcome.walletaddresss
				}
			})
		},
		
	}
</script>

<style scoped>
input{
	width: 90%;
	margin:40rpx auto;
	background-color: #FFFFFF;
	height: 100rpx;
	font-size: 1.1em;
	padding-left: 30rpx;
	color: #7C7C7C;
	}
	.ti{
		position: relative;
	}
	.danwei{
		color: #7C7C7C;
		position: absolute;
		top: 30rpx;
		right: 140rpx;
	}
	.all{
		color: #207DFE;
		position: absolute;
		top: 30rpx;
		right: 60rpx;
	}
	.use{
		position: relative;
		left: 30rpx;
		color: #7C7C7C ;
	}
	.getMoney{
		position: relative;
		top: 44vh;
		font-size: 1.2em;
		left: 30rpx;
		color: #7C7C7C;
	}
	.money{
		padding:0 10rpx;
		color: #FF0000;
	}
	.service{
		position: relative;
		top: 45vh;
		font-size: 1em;
		left: 30rpx;
		color: #7C7C7C;
	}
	button{
		width: 90%;
		margin: auto;
		position: relative;
		top: 47vh;
		color: #FFFFFF;
		background-color: #207DFE;
	}
</style>

